package com.whz.eq;

import java.awt.*;
import java.util.Objects;

/**
 * @Author: sinosoft
 * @Description: 复合优先于继承
 * @Date: Create in 17:27 2021/4/30
 * @Modified By:
 */
public class ColorPoint1 {
    private final Point point;
    private final Color color;

    public ColorPoint1(int x, int y, Color color) {
        this.point = new Point(x, y);
        this.color = Objects.requireNonNull(color);
    }

    /*
    * 返回一个与该有色点处在相同位置的普通Point对象
    * */
    public Point asPoint() {
        return point;
    }

    @Override
    public boolean equals(Object o) {
        if(!(o instanceof ColorPoint1)) {
            return false;
        }
        ColorPoint1 cp = (ColorPoint1) o;
        return Objects.equals(cp.point, point)
                && Objects.equals(cp.color, color);
    }
}
